<!DOCTYPE html>
<html lang=zh>
<head><meta name="generator" content="Hexo 3.8.0">
  <meta charset="utf-8">
  
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no, minimal-ui">
  <meta name="renderer" content="webkit">
  <meta http-equiv="Cache-Control" content="no-transform">
  <meta http-equiv="Cache-Control" content="no-siteapp">
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-status-bar-style" content="black">
  <meta name="format-detection" content="telephone=no,email=no,adress=no">
  <!-- Color theme for statusbar -->
  <meta name="theme-color" content="#000000">
  <!-- 强制页面在当前窗口以独立页面显示,防止别人在框架里调用页面 -->
  <meta http-equiv="window-target" content="_top">
  
  
  <title>用最容易的方式学会单链表（Python实现） | 这是宇宙之一粟的博客</title>
  <meta name="description" content="Python序列类型的本质在本博客中，我们将学习探讨Python的各种“序列”类，内置的三大常用数据结构——列表类（list）、元组类（tuple）和字符串类（str）的本质。 不知道你发现没有，这些类都有一个很明显的共性，都可以用来保存多个数据元素，最主要的功能是：每个类都支持下标（索引）访问该序列的元素，比如使用语法 Seq[i]。其实上面每个类都是使用 数组 这种简单的数据结构表示。 但是熟">
<meta name="keywords" content="数据结构与算法">
<meta property="og:type" content="article">
<meta property="og:title" content="用最容易的方式学会单链表（Python实现）">
<meta property="og:url" content="http://yuzhou_1su.gitee.io/myblogs/2019/11/02/用最复杂的方式学会数组（Python实现动态数组）/index.html">
<meta property="og:site_name" content="小宇的博客">
<meta property="og:description" content="Python序列类型的本质在本博客中，我们将学习探讨Python的各种“序列”类，内置的三大常用数据结构——列表类（list）、元组类（tuple）和字符串类（str）的本质。 不知道你发现没有，这些类都有一个很明显的共性，都可以用来保存多个数据元素，最主要的功能是：每个类都支持下标（索引）访问该序列的元素，比如使用语法 Seq[i]。其实上面每个类都是使用 数组 这种简单的数据结构表示。 但是熟">
<meta property="og:locale" content="zh-CN">
<meta property="og:image" content="https://img-blog.csdnimg.cn/2019110209231525.png">
<meta property="og:image" content="https://img-blog.csdnimg.cn/20191102092352771.png">
<meta property="og:image" content="https://img-blog.csdnimg.cn/20191102095640929.png">
<meta property="og:image" content="https://img-blog.csdnimg.cn/20191102092504695.png">
<meta property="og:updated_time" content="2019-11-02T02:31:28.625Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="用最容易的方式学会单链表（Python实现）">
<meta name="twitter:description" content="Python序列类型的本质在本博客中，我们将学习探讨Python的各种“序列”类，内置的三大常用数据结构——列表类（list）、元组类（tuple）和字符串类（str）的本质。 不知道你发现没有，这些类都有一个很明显的共性，都可以用来保存多个数据元素，最主要的功能是：每个类都支持下标（索引）访问该序列的元素，比如使用语法 Seq[i]。其实上面每个类都是使用 数组 这种简单的数据结构表示。 但是熟">
<meta name="twitter:image" content="https://img-blog.csdnimg.cn/2019110209231525.png">
  <!-- Canonical links -->
  <link rel="canonical" href="http://yuzhou_1su.gitee.io/myblogs/2019/11/02/用最复杂的方式学会数组（Python实现动态数组）/index.html">
  
    <link rel="alternate" href="/atom.xml" title="小宇的博客" type="application/atom+xml">
  
  
    <link rel="icon" href="/favicon.png" type="image/x-icon">
  
  <link rel="stylesheet" href="/myblogs/css/style.css">
  
  
  
  
</head>


<body class="main-center theme-black" itemscope itemtype="http://schema.org/WebPage">
  <header class="header" itemscope itemtype="http://schema.org/WPHeader">
  <div class="slimContent">
    <div class="navbar-header">
      
      
      <div class="profile-block text-center">
        <a id="avatar" href="http://yuzhou_1su.gitee.io/myblogs" target="_blank">
          <img class="img-circle img-rotate" src="/myblogs/images/yuzhou_1su.jpg" width="200" height="200">
        </a>
        <h2 id="name" class="hidden-xs hidden-sm">宇宙之一粟</h2>
        <h3 id="title" class="hidden-xs hidden-sm hidden-md">Python Developer &amp; 阅读爱好者</h3>
        <small id="location" class="text-muted hidden-xs hidden-sm"><i class="icon icon-map-marker"></i> Guangzhou, China</small>
      </div>
      
      <div class="search" id="search-form-wrap">

    <form class="search-form sidebar-form">
        <div class="input-group">
            <input type="text" class="search-form-input form-control" placeholder="搜索">
            <span class="input-group-btn">
                <button type="submit" class="search-form-submit btn btn-flat" onclick="return false;"><i class="icon icon-search"></i></button>
            </span>
        </div>
    </form>
    <div class="ins-search">
  <div class="ins-search-mask"></div>
  <div class="ins-search-container">
    <div class="ins-input-wrapper">
      <input type="text" class="ins-search-input" placeholder="想要查找什么..." x-webkit-speech>
      <button type="button" class="close ins-close ins-selectable" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
    </div>
    <div class="ins-section-wrapper">
      <div class="ins-section-container"></div>
    </div>
  </div>
</div>


</div>
      <button class="navbar-toggle collapsed" type="button" data-toggle="collapse" data-target="#main-navbar" aria-controls="main-navbar" aria-expanded="false">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
    </div>
    <nav id="main-navbar" class="collapse navbar-collapse" itemscope itemtype="http://schema.org/SiteNavigationElement" role="navigation">
      <ul class="nav navbar-nav main-nav ">
        
        
        <li class="menu-item menu-item-home">
          <a href="/myblogs/.">
            
            <i class="icon icon-home-fill"></i>
            
            <span class="menu-title">首页</span>
          </a>
        </li>
        
        
        <li class="menu-item menu-item-archives">
          <a href="/myblogs/archives">
            
            <i class="icon icon-archives-fill"></i>
            
            <span class="menu-title">归档</span>
          </a>
        </li>
        
        
        <li class="menu-item menu-item-about">
          <a href="/myblogs/about">
            
            <i class="icon icon-cup-fill"></i>
            
            <span class="menu-title">关于</span>
          </a>
        </li>
        
      </ul>
      
	
    <ul class="social-links">
    	
        <li><a href="https://github.com/yuzhouStayHungry" target="_blank" title="Github" data-toggle="tooltip" data-placement="top"><i class="icon icon-github"></i></a></li>
        
        <li><a href="https://www.jianshu.com/u/93e9b14c6fbd" target="_blank" title="简书" data-toggle="tooltip" data-placement="top"><i class="icon icon-简书"></i></a></li>
        
        <li><a href="https://www.cnblogs.com/yuzhou-1su/" target="_blank" title="Blog" data-toggle="tooltip" data-placement="top"><i class="icon icon-Blog"></i></a></li>
        
        <li><a href="https://blog.csdn.net/yuzhou_1shu" target="_blank" title="CSDN" data-toggle="tooltip" data-placement="top"><i class="icon icon-CSDN"></i></a></li>
        
        <li><a href="/myblogs/atom.xml" target="_blank" title="Rss" data-toggle="tooltip" data-placement="top"><i class="icon icon-rss"></i></a></li>
        
    </ul>

    </nav>
  </div>
</header>

  
    <aside class="sidebar" itemscope itemtype="http://schema.org/WPSideBar">
  <div class="slimContent">
    
      <div class="widget">
    <h3 class="widget-title">公告</h3>
    <div class="widget-body">
        <div id="board">
            <div class="content">
                <p> 欢迎一起探讨跟学习 </p>
            </div>
        </div>
    </div>
</div>

    
      
  <div class="widget">
    <h3 class="widget-title">分类</h3>
    <div class="widget-body">
      <ul class="category-list"><li class="category-list-item"><a class="category-list-link" href="/myblogs/categories/技术/">技术</a><span class="category-list-count">3</span></li><li class="category-list-item"><a class="category-list-link" href="/myblogs/categories/文学/">文学</a><span class="category-list-count">3</span></li></ul>
    </div>
  </div>


    
      
  <div class="widget">
    <h3 class="widget-title">标签</h3>
    <div class="widget-body">
      <ul class="tag-list"><li class="tag-list-item"><a class="tag-list-link" href="/myblogs/tags/hexo配置/">hexo配置</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/myblogs/tags/数据结构与算法/">数据结构与算法</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/myblogs/tags/读书笔记/">读书笔记</a><span class="tag-list-count">3</span></li></ul>
    </div>
  </div>


    
      
  <div class="widget">
    <h3 class="widget-title">标签云</h3>
    <div class="widget-body tagcloud">
      <a href="/myblogs/tags/hexo配置/" style="font-size: 13px;">hexo配置</a> <a href="/myblogs/tags/数据结构与算法/" style="font-size: 13.5px;">数据结构与算法</a> <a href="/myblogs/tags/读书笔记/" style="font-size: 14px;">读书笔记</a>
    </div>
  </div>

    
      
  <div class="widget">
    <h3 class="widget-title">归档</h3>
    <div class="widget-body">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/myblogs/archives/2019/11/">十一月 2019</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/myblogs/archives/2019/10/">十月 2019</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/myblogs/archives/2019/07/">七月 2019</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/myblogs/archives/2019/06/">六月 2019</a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="/myblogs/archives/2019/05/">五月 2019</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/myblogs/archives/2018/07/">七月 2018</a><span class="archive-list-count">1</span></li></ul>
    </div>
  </div>


    
      
  <div class="widget">
    <h3 class="widget-title">最新文章</h3>
    <div class="widget-body">
      <ul class="recent-post-list list-unstyled no-thumbnail">
        
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                <a class="category-link" href="/myblogs/categories/技术/">技术</a>
              </p>
              <p class="item-title">
                <a href="/myblogs/2019/11/02/用最复杂的方式学会数组（Python实现动态数组）/" class="title">用最容易的方式学会单链表（Python实现）</a>
              </p>
              <p class="item-date">
                <time datetime="2019-11-02T02:26:58.362Z" itemprop="datePublished">2019-11-02</time>
              </p>
            </div>
          </li>
          
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                <a class="category-link" href="/myblogs/categories/技术/">技术</a>
              </p>
              <p class="item-title">
                <a href="/myblogs/2019/10/30/用最容易的方式学会单链表（Python实现）/" class="title">用最容易的方式学会单链表（Python实现）</a>
              </p>
              <p class="item-date">
                <time datetime="2019-10-30T09:52:30.000Z" itemprop="datePublished">2019-10-30</time>
              </p>
            </div>
          </li>
          
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                <a class="category-link" href="/myblogs/categories/文学/">文学</a>
              </p>
              <p class="item-title">
                <a href="/myblogs/2019/07/18/如何写作/" class="title">如何高效写作</a>
              </p>
              <p class="item-date">
                <time datetime="2019-07-18T09:52:30.000Z" itemprop="datePublished">2019-07-18</time>
              </p>
            </div>
          </li>
          
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                <a class="category-link" href="/myblogs/categories/文学/">文学</a>
              </p>
              <p class="item-title">
                <a href="/myblogs/2019/06/30/《沟通圣经》/" class="title">读《沟通圣经》</a>
              </p>
              <p class="item-date">
                <time datetime="2019-06-30T12:52:30.000Z" itemprop="datePublished">2019-06-30</time>
              </p>
            </div>
          </li>
          
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                
              </p>
              <p class="item-title">
                <a href="/myblogs/2019/06/30/SQ3R阅读法/" class="title">SQ3R阅读法</a>
              </p>
              <p class="item-date">
                <time datetime="2019-06-30T12:52:30.000Z" itemprop="datePublished">2019-06-30</time>
              </p>
            </div>
          </li>
          
      </ul>
    </div>
  </div>
  

    
  </div>
</aside>

  
  
<aside class="sidebar sidebar-toc collapse" id="collapseToc" itemscope itemtype="http://schema.org/WPSideBar">
  <div class="slimContent">
    <nav id="toc" class="article-toc">
      <h3 class="toc-title">文章目录</h3>
      <ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#Python序列类型的本质"><span class="toc-number">1.</span> <span class="toc-text">Python序列类型的本质</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#计算机内存中的数组结构"><span class="toc-number">1.1.</span> <span class="toc-text">计算机内存中的数组结构</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Python列表"><span class="toc-number">1.2.</span> <span class="toc-text">Python列表</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#Python列表的操作"><span class="toc-number">1.2.1.</span> <span class="toc-text">Python列表的操作</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Python列表的内存分配背后的基础知识"><span class="toc-number">1.2.2.</span> <span class="toc-text">Python列表的内存分配背后的基础知识</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#动态数组"><span class="toc-number">1.3.</span> <span class="toc-text">动态数组</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#什么是动态数组"><span class="toc-number">1.3.1.</span> <span class="toc-text">什么是动态数组</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#实现动态数组的Python代码"><span class="toc-number">1.3.2.</span> <span class="toc-text">实现动态数组的Python代码</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#测试动态数组Python代码"><span class="toc-number">1.3.3.</span> <span class="toc-text">测试动态数组Python代码</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#测试结果"><span class="toc-number">1.3.4.</span> <span class="toc-text">测试结果</span></a></li></ol></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#总结"><span class="toc-number">2.</span> <span class="toc-text">总结</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#推广"><span class="toc-number">3.</span> <span class="toc-text">推广</span></a></li></ol>
    </nav>
  </div>
</aside>

<main class="main" role="main">
  <div class="content">
  <article id="post-用最复杂的方式学会数组（Python实现动态数组）" class="article article-type-post" itemscope itemtype="http://schema.org/BlogPosting">
    
    <div class="article-header">
      
        
  
    <h1 class="article-title" itemprop="name">
      用最容易的方式学会单链表（Python实现）
    </h1>
  

      
      <div class="article-meta">
        <span class="article-date">
    <i class="icon icon-calendar-check"></i>
	<a href="/myblogs/2019/11/02/用最复杂的方式学会数组（Python实现动态数组）/" class="article-date">
	  <time datetime="2019-11-02T02:26:58.362Z" itemprop="datePublished">2019-11-02</time>
	</a>
</span>
        
  <span class="article-category">
    <i class="icon icon-folder"></i>
    <a class="article-category-link" href="/myblogs/categories/技术/">技术</a>
  </span>

        
  <span class="article-tag">
    <i class="icon icon-tags"></i>
	<a class="article-tag-link" href="/myblogs/tags/数据结构与算法/">数据结构与算法</a>
  </span>


        

        <span class="post-comment"><i class="icon icon-comment"></i> <a href="/myblogs/2019/11/02/用最复杂的方式学会数组（Python实现动态数组）/#comments" class="article-comment-link">评论</a></span>
        
      </div>
    </div>
    <div class="article-entry marked-body" itemprop="articleBody">
      
        <h1 id="Python序列类型的本质"><a href="#Python序列类型的本质" class="headerlink" title="Python序列类型的本质"></a>Python序列类型的本质</h1><p>在本博客中，我们将学习探讨Python的各种“序列”类，内置的三大常用数据结构——列表类（list）、元组类（tuple）和字符串类（str）的本质。</p>
<p>不知道你发现没有，这些类都有一个很明显的共性，都可以用来保存多个数据元素，最主要的功能是：每个类都支持下标（索引）访问该序列的元素，比如使用语法 <code>Seq[i]</code>。其实上面每个类都是使用 <code>数组</code> 这种简单的数据结构表示。</p>
<p>但是熟悉Python的读者可能知道这3种数据结构又有一些不同：比如元组和字符串是不能修改的，列表可以修改。</p>
<h2 id="计算机内存中的数组结构"><a href="#计算机内存中的数组结构" class="headerlink" title="计算机内存中的数组结构"></a>计算机内存中的数组结构</h2><p>计算机体系结构中，我们知道计算机主存由位信息组成，这些位通常被归类成更大的单元，这些单元则取决于精准的系统架构。一个典型的单元就是一个字节，相当于8位。</p>
<p>计算机系统拥有庞大数量的存储字节，那么如何才能找到我们的信息存在哪个字节呢？答案就是大家平时熟知的 <code>存储地址</code> 。基于存储地址，主存中的任何字节都能被有效的访问。实际上，每个存储字节都和一个作为其地址的唯一二进制数字相关联。如下图中，每个字节均被指定了存储地址：</p>
<p><img src="https://img-blog.csdnimg.cn/2019110209231525.png" alt></p>
<p>一般来说，<strong>编程语言</strong>记录标识符和其关联值所存储的地址之间的关系。比如，当我们声明标识符  $x$ 就有可能和存储器中的某一值相关联，而标识符 $y$就可能和其他的值相关联。一组相关的变量能够一个接一个地存储在计算机存储器的一块连续区域内。我们将这种方式称为 <strong>数组</strong>。</p>
<p>我们来看Python中的例子，一个文本字符串 <code>HELLO</code> 是以一列有序字符的形式存储的，假定该字符串的每个Unicode字符需要两个字节的存储空间。最下面的数字就是该字符串的索引值。</p>
<p><img src="https://img-blog.csdnimg.cn/20191102092352771.png" alt></p>
<p>我们可以看到，数组可以存储多个值而无需构造具有特定索引的多个变量来指定其中的每个项目，并且几乎在所有编程语言（例如C、Java、C#、C++）中使用，但是Python更具有优势。Python在构建列表时，熟悉的读者可能知道，不需要预先定义数组或列表的大小，相反，在Python中，列表具有动态性质，我们可以不断的往列表中添加我们想要的数据元素。接下来，让我们看看Python列表的知识（已经熟悉的读者可以快速浏览或者跳过）。</p>
<h2 id="Python列表"><a href="#Python列表" class="headerlink" title="Python列表"></a>Python列表</h2><h3 id="Python列表的操作"><a href="#Python列表的操作" class="headerlink" title="Python列表的操作"></a>Python列表的操作</h3><ul>
<li>创建列表的语法格式：</li>
</ul>
<p><code>[ele1, ele2, ele3, ele4, ...]</code></p>
<ul>
<li>创建元组的语法格式：</li>
</ul>
<p><code>(ele1, ele2, ele3, ele4, ...)</code> </p>
<p>元组比列表的内存空间利用率更高，因为元组是固定不变的，所以没有必要创建拥有剩余空间的动态数组。</p>
<p>我们先在Python的IDE中创建一个列表，然后大致了解一下列表部分内置操作，我们先创建了一个名为test_list的列表，然后修改（插入或删除）元素，反转或清空列表，具体如下：</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&gt;&gt;&gt; </span>test_list = []	<span class="comment"># 创建名为test_list的空列表</span></span><br><span class="line"><span class="meta">&gt;&gt;&gt; </span>test_list.append(<span class="string">"Hello"</span>)</span><br><span class="line"><span class="meta">&gt;&gt;&gt; </span>test_list.append(<span class="string">"World"</span>)</span><br><span class="line"><span class="meta">&gt;&gt;&gt; </span>test_list</span><br><span class="line">[<span class="string">'Hello'</span>, <span class="string">'World'</span>]</span><br><span class="line"><span class="meta">&gt;&gt;&gt; </span>test_list = [<span class="string">"Hello"</span>, <span class="string">"Array"</span>, <span class="number">2019</span>, <span class="string">"easy learning"</span>, <span class="string">"DataStructure"</span>]	<span class="comment"># 重新给test_list赋值</span></span><br><span class="line"><span class="meta">&gt;&gt;&gt; </span>len(test_list)	<span class="comment"># 求列表的长度</span></span><br><span class="line"><span class="number">5</span></span><br><span class="line"><span class="meta">&gt;&gt;&gt; </span>test_list[<span class="number">2</span>] = <span class="number">1024</span>	<span class="comment"># 修改列表元素</span></span><br><span class="line"><span class="meta">&gt;&gt;&gt; </span>test_list</span><br><span class="line">[<span class="string">'Hello'</span>, <span class="string">'Array'</span>, <span class="number">1024</span>, <span class="string">'easy learning'</span>, <span class="string">'DataStructure'</span>]</span><br><span class="line">&gt;&gt;&gt;</span><br><span class="line"><span class="meta">&gt;&gt;&gt; </span>test_list.insert(<span class="number">1</span>, <span class="string">"I love"</span>)	<span class="comment"># 向列表中指定位置中插入一个元素</span></span><br><span class="line"><span class="meta">&gt;&gt;&gt; </span>test_list</span><br><span class="line">[<span class="string">'Hello'</span>, <span class="string">'I love'</span>, <span class="string">'Array'</span>, <span class="number">1024</span>, <span class="string">'easy learning'</span>, <span class="string">'DataStructure'</span>]</span><br><span class="line"><span class="meta">&gt;&gt;&gt; </span>test_list.append(<span class="number">2020</span>)	<span class="comment"># 向列表末尾增加一个元素</span></span><br><span class="line"><span class="meta">&gt;&gt;&gt; </span>test_list</span><br><span class="line">[<span class="string">'Hello'</span>, <span class="string">'I love'</span>, <span class="string">'Array'</span>, <span class="number">1024</span>, <span class="string">'easy learning'</span>, <span class="string">'DataStructure'</span>, <span class="number">2020</span>]</span><br><span class="line">&gt;&gt;&gt;</span><br><span class="line"><span class="meta">&gt;&gt;&gt; </span>test_list.pop(<span class="number">1</span>)	<span class="comment"># 删除指定位置的元素</span></span><br><span class="line"><span class="string">'I love'</span></span><br><span class="line"><span class="meta">&gt;&gt;&gt; </span>test_list.remove(<span class="number">2020</span>)	<span class="comment"># 删除指定元素</span></span><br><span class="line"><span class="meta">&gt;&gt;&gt; </span></span><br><span class="line"><span class="meta">&gt;&gt;&gt; </span>test_list.index(<span class="string">'Hello'</span>)	<span class="comment"># 查找某个元素的索引值</span></span><br><span class="line"><span class="number">0</span></span><br><span class="line"><span class="meta">&gt;&gt;&gt; </span>test_list.index(<span class="string">'hello'</span>)	<span class="comment"># 如果查找某个元素不在列表中，返回ValueError错误</span></span><br><span class="line">Traceback (most recent call last):</span><br><span class="line">  File <span class="string">"&lt;pyshell#11&gt;"</span>, line <span class="number">1</span>, <span class="keyword">in</span> &lt;module&gt;</span><br><span class="line">    test_list.index(<span class="string">'hello'</span>)</span><br><span class="line">ValueError: <span class="string">'hello'</span> <span class="keyword">is</span> <span class="keyword">not</span> <span class="keyword">in</span> list</span><br><span class="line"><span class="meta">&gt;&gt;&gt; </span></span><br><span class="line"><span class="meta">&gt;&gt;&gt; </span>test_list.reverse()	<span class="comment"># 反转整个列表</span></span><br><span class="line"><span class="meta">&gt;&gt;&gt; </span>test_list</span><br><span class="line">[<span class="string">'DataStructure'</span>, <span class="string">'easy learning'</span>, <span class="number">2019</span>, <span class="string">'Array'</span>, <span class="string">'Hello'</span>]</span><br><span class="line"><span class="meta">&gt;&gt;&gt; </span>test_list.clear()	<span class="comment"># 清空列表</span></span><br><span class="line"><span class="meta">&gt;&gt;&gt; </span>test_list</span><br><span class="line">[]</span><br></pre></td></tr></table></figure>

<p>我们看上面的代码，可以看到list的相关操作——增删改查，已经很强大了，还有一些内置方法这里并没有做展示，留给读者自己去发现并体验。</p>
<h3 id="Python列表的内存分配背后的基础知识"><a href="#Python列表的内存分配背后的基础知识" class="headerlink" title="Python列表的内存分配背后的基础知识"></a>Python列表的内存分配背后的基础知识</h3><p>因此，让我们通过编码实践以及内存中保存的数组的实际大小与给定大小之间的关系来查看这种额外的空间演示。</p>
<p>前往Jupyter notebook进行练习。或者使用自己选择的任何编辑器或开发环境。复制下面编写的代码。</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 导入sys模块能方便我们使用gestsizeof函数</span></span><br><span class="line"><span class="keyword">import</span> sys</span><br><span class="line"></span><br><span class="line"><span class="comment"># set n</span></span><br><span class="line">n = <span class="number">20</span></span><br><span class="line"><span class="comment"># set empty list</span></span><br><span class="line">list = []</span><br><span class="line"><span class="keyword">for</span> i <span class="keyword">in</span> range(n):</span><br><span class="line">    a = len(list)</span><br><span class="line">    <span class="comment"># 调用getsizeof函数用于给出Python中存储对象的真实字节数</span></span><br><span class="line">    b = sys.getsizeof(list)</span><br><span class="line">    print(<span class="string">'Length:&#123;0:3d&#125;; Size of bytes:&#123;1:4d&#125;'</span>.format(a, b))</span><br><span class="line">    <span class="comment"># Increase length by one</span></span><br><span class="line">    list.append(n)</span><br></pre></td></tr></table></figure>

<p>运行代码，可以看到如下输出：<br><img src="https://img-blog.csdnimg.cn/20191102095640929.png" alt="在这里插入图片描述"><br>现在，随着我们增加列表的长度，字节也增加了。我们分析一下，<code>Length：1</code>位置的元素填入列表时，字节数从64跳到96，增加了32个字节。因为本实验是在64位机器上运行的，这表明每个内存地址是64位（即8个字节）。增加的32个字节即为分配的用于存储4个对象引用的数组大小。当增加第2个、第3个或者第4个元素时，内存占用没有任何改变。字节数96能够提供4个对象的引用。<br>$$<br>96\ =\ 64\ +\ 8\ \times \ 4<br>$$<br>当<code>Length:10</code>时，字节数从一开始的64跳到192，能存下16个对象的引用，<br>$$<br>192\ =\ 64\ +\ 8\ \times \ 16<br>$$<br>一直到<code>Length: 17</code>后又开始跳转，所以理论上264个字节数应该可以存下25个对象<br>$$<br>264\ =\ 64\ +\ 8\ \times \ 25<br>$$<br>但因为我们在代码中设置<code>n=20</code>，然后程序就终止了。</p>
<p>我们可以看到Python内置的list类足够智能，知道当需要额外的空间来分配数据时，它会为它们提供额外的大小，那么这究竟是如何被实现的呢？</p>
<p>好吧，答案是<strong>动态数组</strong>。说到这里，不知道大家学Python列表的时候是不是这样想的——列表很简单嘛，就是list()类、用中括号[]括起来，然后指导书籍或文档上的各类方法append、insert、pop…在各种IDE一顿操作过后，是的我觉得我学会了。</p>
<p>但其实背后的原理真的很不简单，比如我举个例子：<code>A[-1]</code>这个操作怎么实现？列表切片功能怎么实现？如何自己写pop()默认删除列表最右边的元素(popleft删除最左边简单)？…这些功能用起来爽，但真的自己实现太难了（我也还在学习中，大佬们请轻喷！）如果我们能学习并理解，肯定可以加强我们对数组这一结构的理解。</p>
<h2 id="动态数组"><a href="#动态数组" class="headerlink" title="动态数组"></a>动态数组</h2><h3 id="什么是动态数组"><a href="#什么是动态数组" class="headerlink" title="什么是动态数组"></a>什么是动态数组</h3><p>动态数组是内存的连续区域，其大小随着插入新数据而动态增长。在静态数组中，我们需要在分配时指定大小。在定义数组的时候，其实计算机已经帮我们分配好了内存来存储，实际上我们不能扩展数组，因为它的大小是固定的。比如：我们分配一个大小为10的数组，则不能插入超过10个项目。</p>
<p>但是动态数组会在需要的时候自动调整其大小。这一点有点像我们使用的Python列表，可以存储任意数量的项目，而无需在分配时指定大小。</p>
<p>所以实现一个动态数组的实现的关键是——如何扩展数组？当列表<strong>list1</strong>的大小已满时，而此时有新的元素要添加进列表，我们会执行一下步骤来克服其大小限制的缺点：</p>
<ol>
<li>分配具有更大容量的新数组 <strong>list2</strong> </li>
<li>设置 <strong>list2[i] = list1[i]</strong> (i=0,1,2,…，n-1)，其中n是该项目的当前编号</li>
<li>设置<strong>list1 = list2</strong>，也就是说，list2正在作为新的数组来引用我们的新列表。</li>
<li>然后，只要将新的元素插入（添加）到我们的列表list1即可。</li>
</ol>
<p><img src="https://img-blog.csdnimg.cn/20191102092504695.png" alt></p>
<p>接下来要思考的问题是，新数组应该多大？通常我们得做法是：新数组的大小是已满的旧数组的2倍。我们将在Python中编程实现动态数组的概念，并创建一个简单的代码，很多功能不及Python强大。</p>
<h3 id="实现动态数组的Python代码"><a href="#实现动态数组的Python代码" class="headerlink" title="实现动态数组的Python代码"></a>实现动态数组的Python代码</h3><p>在Python中，我们利用ctypes的内置库来创建自己的动态数组类，因为<a href="https://docs.python.org/zh-cn/3/library/ctypes.html?highlight=ctype#module-ctypes" target="_blank" rel="noopener">ctypes模块</a>提供对原始数组的支持，为了更快的对数组进行学习，所以对ctypes的知识可以查看官方文档进行学习。关于Python的公有方法与私有方法，我们在方法名称前使用双下划线<strong>__</strong>使其保持隐藏状态，代码如下：</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># -*- coding: utf-8 -*-</span></span><br><span class="line"><span class="comment"># @Time      : 2019-11-01 17:10</span></span><br><span class="line"><span class="comment"># @Author    : yuzhou_1su</span></span><br><span class="line"><span class="comment"># @ContactMe : https://blog.csdn.net/yuzhou_1shu</span></span><br><span class="line"><span class="comment"># @File      : DynamicArray.py</span></span><br><span class="line"><span class="comment"># @Software  : PyCharm</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> ctypes</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">DynamicArray</span>:</span></span><br><span class="line">    <span class="string">"""A dynamic array class akin to a simplified Python list."""</span></span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">__init__</span><span class="params">(self)</span>:</span></span><br><span class="line">        <span class="string">"""Create an empty array."""</span></span><br><span class="line">        self.n = <span class="number">0</span>             <span class="comment"># count actual elements</span></span><br><span class="line">        self.capacity = <span class="number">1</span>      <span class="comment"># default array capacity</span></span><br><span class="line">        self.A = self._make_array(self.capacity)      <span class="comment"># low-level array</span></span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">is_empty</span><span class="params">(self)</span>:</span></span><br><span class="line">        <span class="string">""" Return True if array is empty"""</span></span><br><span class="line">        <span class="keyword">return</span> self.n == <span class="number">0</span></span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">__len__</span><span class="params">(self)</span>:</span></span><br><span class="line">        <span class="string">"""Return numbers of elements stored in the array."""</span></span><br><span class="line">        <span class="keyword">return</span> self.n</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">__getitem__</span><span class="params">(self, i)</span>:</span></span><br><span class="line">        <span class="string">"""Return element at index i."""</span></span><br><span class="line">        <span class="keyword">if</span> <span class="keyword">not</span> <span class="number">0</span> &lt;= i &lt; self.n:</span><br><span class="line">            <span class="comment"># Check it i index is in bounds of array</span></span><br><span class="line">            <span class="keyword">raise</span> ValueError(<span class="string">'invalid index'</span>)</span><br><span class="line">        <span class="keyword">return</span> self.A[i]</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">append</span><span class="params">(self, obj)</span>:</span></span><br><span class="line">        <span class="string">"""Add object to end of the array."""</span></span><br><span class="line">        <span class="keyword">if</span> self.n == self.capacity:</span><br><span class="line">            <span class="comment"># Double capacity if not enough room</span></span><br><span class="line">            self._resize(<span class="number">2</span> * self.capacity)</span><br><span class="line">        self.A[self.n] = obj    <span class="comment"># Set self.n index to obj</span></span><br><span class="line">        self.n += <span class="number">1</span></span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">_resize</span><span class="params">(self, c)</span>:</span></span><br><span class="line">        <span class="string">"""Resize internal array to capacity c."""</span></span><br><span class="line">        B = self._make_array(c)     <span class="comment"># New bigger array</span></span><br><span class="line">        <span class="keyword">for</span> k <span class="keyword">in</span> range(self.n):    <span class="comment"># Reference all existing values</span></span><br><span class="line">            B[k] = self.A[k]</span><br><span class="line">        self.A = B          <span class="comment"># Call A the new bigger array</span></span><br><span class="line">        self.capacity = c   <span class="comment"># Reset the capacity</span></span><br><span class="line"></span><br><span class="line"><span class="meta">    @staticmethod</span></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">_make_array</span><span class="params">(c)</span>:</span></span><br><span class="line">        <span class="string">"""Return new array with capacity c."""</span></span><br><span class="line">        <span class="keyword">return</span> (c * ctypes.py_object)()</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">insert</span><span class="params">(self, k, value)</span>:</span></span><br><span class="line">        <span class="string">"""Insert value at position k."""</span></span><br><span class="line">        <span class="keyword">if</span> self.n == self.capacity:</span><br><span class="line">            self._resize(<span class="number">2</span> * self.capacity)</span><br><span class="line">        <span class="keyword">for</span> j <span class="keyword">in</span> range(self.n, k, <span class="number">-1</span>):</span><br><span class="line">            self.A[j] = self.A[j<span class="number">-1</span>]</span><br><span class="line">        self.A[k] = value</span><br><span class="line">        self.n += <span class="number">1</span></span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">pop</span><span class="params">(self, index=<span class="number">0</span>)</span>:</span></span><br><span class="line">        <span class="string">"""Remove item at index (default first)."""</span></span><br><span class="line">        <span class="keyword">if</span> index &gt;= self.n <span class="keyword">or</span> index &lt; <span class="number">0</span>:</span><br><span class="line">            <span class="keyword">raise</span> ValueError(<span class="string">'invalid index'</span>)</span><br><span class="line">        <span class="keyword">for</span> i <span class="keyword">in</span> range(index, self.n<span class="number">-1</span>):</span><br><span class="line">            self.A[i] = self.A[i+<span class="number">1</span>]</span><br><span class="line">        self.A[self.n - <span class="number">1</span>] = <span class="literal">None</span></span><br><span class="line">        self.n -= <span class="number">1</span></span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">remove</span><span class="params">(self, value)</span>:</span></span><br><span class="line">        <span class="string">"""Remove the first occurrence of a value in the array."""</span></span><br><span class="line">        <span class="keyword">for</span> k <span class="keyword">in</span> range(self.n):</span><br><span class="line">            <span class="keyword">if</span> self.A[k] == value:</span><br><span class="line">                <span class="keyword">for</span> j <span class="keyword">in</span> range(k, self.n - <span class="number">1</span>):</span><br><span class="line">                    self.A[j] = self.A[j+<span class="number">1</span>]</span><br><span class="line">                self.A[self.n - <span class="number">1</span>] = <span class="literal">None</span></span><br><span class="line">                self.n -= <span class="number">1</span></span><br><span class="line">                <span class="keyword">return</span></span><br><span class="line">        <span class="keyword">raise</span> ValueError(<span class="string">'value not found'</span>)</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">_print</span><span class="params">(self)</span>:</span></span><br><span class="line">        <span class="string">"""Print the array."""</span></span><br><span class="line">        <span class="keyword">for</span> i <span class="keyword">in</span> range(self.n):</span><br><span class="line">            print(self.A[i], end=<span class="string">' '</span>)</span><br><span class="line">        print()</span><br></pre></td></tr></table></figure>

<h3 id="测试动态数组Python代码"><a href="#测试动态数组Python代码" class="headerlink" title="测试动态数组Python代码"></a>测试动态数组Python代码</h3><p>上面我们已经实现了一个动态数组的类，相信都很激动，接下来让我们来测试一下，看能不能成功呢？在同一个文件下，写的测试代码如下：</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">main</span><span class="params">()</span>:</span></span><br><span class="line">    <span class="comment"># Instantiate</span></span><br><span class="line">    mylist = DynamicArray()</span><br><span class="line"></span><br><span class="line">    <span class="comment"># Append new element</span></span><br><span class="line">    mylist.append(<span class="number">10</span>)</span><br><span class="line">    mylist.append(<span class="number">9</span>)</span><br><span class="line">    mylist.append(<span class="number">8</span>)</span><br><span class="line">    <span class="comment"># Insert new element in given position</span></span><br><span class="line">    mylist.insert(<span class="number">1</span>, <span class="number">1024</span>)</span><br><span class="line">    mylist.insert(<span class="number">2</span>, <span class="number">2019</span>)</span><br><span class="line">    <span class="comment"># Check length</span></span><br><span class="line">    print(<span class="string">'The array length is: '</span>, mylist.__len__())</span><br><span class="line">    <span class="comment"># Print the array</span></span><br><span class="line">    print(<span class="string">'Print the array：'</span>)</span><br><span class="line">    mylist._print()</span><br><span class="line">    <span class="comment"># Index</span></span><br><span class="line">    print(<span class="string">'The element at index 1 is :'</span>, mylist[<span class="number">1</span>])</span><br><span class="line">    <span class="comment"># Remove element</span></span><br><span class="line">    print(<span class="string">'Remove 2019 in array:'</span>)</span><br><span class="line">    mylist.remove(<span class="number">2019</span>)</span><br><span class="line">    mylist._print()</span><br><span class="line">    <span class="comment"># Pop element in given position</span></span><br><span class="line">    print(<span class="string">'Pop pos 2 in array:'</span>)</span><br><span class="line">    <span class="comment"># mylist.pop()</span></span><br><span class="line">    mylist.pop(<span class="number">2</span>)</span><br><span class="line">    mylist._print()</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="keyword">if</span> __name__ == <span class="string">'__main__'</span>:</span><br><span class="line">    main()</span><br></pre></td></tr></table></figure>

<h3 id="测试结果"><a href="#测试结果" class="headerlink" title="测试结果"></a>测试结果</h3><p>激动人心的时刻揭晓，测试结果如下。请结合测试代码和数组的结构进行理解，如果由疏漏，欢迎大家指出。</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">The array length <span class="keyword">is</span>:  <span class="number">5</span></span><br><span class="line">Print the array：</span><br><span class="line"><span class="number">10</span> <span class="number">1024</span> <span class="number">2019</span> <span class="number">9</span> <span class="number">8</span> </span><br><span class="line">The element at index <span class="number">1</span> <span class="keyword">is</span> : <span class="number">1024</span></span><br><span class="line">Remove <span class="number">2019</span> <span class="keyword">in</span> array:</span><br><span class="line"><span class="number">10</span> <span class="number">1024</span> <span class="number">9</span> <span class="number">8</span> </span><br><span class="line">Pop pos <span class="number">2</span> <span class="keyword">in</span> array:</span><br><span class="line"><span class="number">10</span> <span class="number">1024</span> <span class="number">8</span></span><br></pre></td></tr></table></figure>

<h1 id="总结"><a href="#总结" class="headerlink" title="总结"></a>总结</h1><p>通过以上的介绍，我们知道了<strong>数组</strong>存在静态和动态类型。对应到Python——列表就是动态数组，而元组和字符串就是静态数组。<br>而在本博客中，我们着重介绍了什么是动态数组，并通过Python代码进行实现。希望你能从此以复杂的方式学会数组。<br>总结发言，看似简单的操作，背后实现原理可能很复杂。</p>
<h1 id="推广"><a href="#推广" class="headerlink" title="推广"></a>推广</h1><p>人生格言：觉宇宙之无穷，渺沧海之一粟<br>自我介绍：文理兼修但不都精通的码农</p>
<p>同名公众号：宇宙之一粟（yuzhou_1su）<br>同名简书：<a href="https://www.jianshu.com/u/93e9b14c6fbd" target="_blank" rel="noopener">https://www.jianshu.com/u/93e9b14c6fbd</a><br>同名博客园：<a href="https://www.cnblogs.com/yuzhou-1su/" target="_blank" rel="noopener">https://www.cnblogs.com/yuzhou-1su/</a><br>同名CSDN：<a href="https://blog.csdn.net/yuzhou_1shu" target="_blank" rel="noopener">https://blog.csdn.net/yuzhou_1shu</a></p>

      
    </div>
    <div class="article-footer">
      <blockquote class="mt-2x">
  <ul class="post-copyright list-unstyled">
    
    <li class="post-copyright-link hidden-xs">
      <strong>本文链接：</strong>
      <a href="http://yuzhou_1su.gitee.io/myblogs/2019/11/02/用最复杂的方式学会数组（Python实现动态数组）/" title="用最容易的方式学会单链表（Python实现）" target="_blank" rel="external">http://yuzhou_1su.gitee.io/myblogs/2019/11/02/用最复杂的方式学会数组（Python实现动态数组）/</a>
    </li>
    
    <li class="post-copyright-license">
      <strong>版权声明： </strong> 本博客所有文章除特别声明外，均采用 <a href="http://creativecommons.org/licenses/by/4.0/deed.zh" target="_blank" rel="external">CC BY 4.0 CN协议</a> 许可协议。转载请注明出处！
    </li>
  </ul>
</blockquote>


<div class="panel panel-default panel-badger">
  <div class="panel-body">
    <figure class="media">
      <div class="media-left">
        <a href="http://yuzhou_1su.gitee.io/myblogs" target="_blank" class="img-burn thumb-sm visible-lg">
          <img src="/myblogs/images/yuzhou_1su.jpg" class="img-rounded w-full" alt>
        </a>
      </div>
      <div class="media-body">
        <h3 class="media-heading"><a href="http://yuzhou_1su.gitee.io/myblogs" target="_blank"><span class="text-dark">宇宙之一粟</span><small class="ml-1x">Python Developer &amp; 阅读爱好者</small></a></h3>
        <div>觉宇宙之无穷，渺沧海之一粟。文理兼修但不都精通的码农</div>
      </div>
    </figure>
  </div>
</div>


    </div>
  </article>
  
    
  <section id="comments">
  	
      <div id="vcomments"></div>
    
  </section>


  
</div>

  <nav class="bar bar-footer clearfix" data-stick-bottom>
  <div class="bar-inner">
  
  <ul class="pager pull-left">
    
    
    <li class="next">
      <a href="/myblogs/2019/10/30/用最容易的方式学会单链表（Python实现）/" title="用最容易的方式学会单链表（Python实现）"><span>下一篇&nbsp;&nbsp;</span><i class="icon icon-angle-right" aria-hidden="true"></i></a>
    </li>
    
    
    <li class="toggle-toc">
      <a class="toggle-btn collapsed" data-toggle="collapse" href="#collapseToc" aria-expanded="false" title="文章目录" role="button">
        <span>[&nbsp;</span><span>文章目录</span>
        <i class="text-collapsed icon icon-anchor"></i>
        <i class="text-in icon icon-close"></i>
        <span>]</span>
      </a>
    </li>
    
  </ul>
  
  
  <!-- Button trigger modal -->
  <button type="button" class="btn btn-fancy btn-donate pop-onhover bg-gradient-warning" data-toggle="modal" data-target="#donateModal"><span>赏</span></button>
  <!-- <div class="wave-icon wave-icon-danger btn-donate" data-toggle="modal" data-target="#donateModal">
    <div class="wave-circle"><span class="icon"><i class="icon icon-bill"></i></span></div>
  </div> -->
  
  
  <div class="bar-right">
    
    <div class="share-component" data-sites="weibo,qq,wechat,facebook,twitter" data-mobile-sites="weibo,qq,qzone"></div>
    
  </div>
  </div>
</nav>
  
<!-- Modal -->
<div class="modal modal-center modal-small modal-xs-full fade" id="donateModal" tabindex="-1" role="dialog">
  <div class="modal-dialog" role="document">
    <div class="modal-content donate">
      <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
      <div class="modal-body">
        <div class="donate-box">
          <div class="donate-head">
            <p>感谢您的支持，我会继续努力的!</p>
          </div>
          <div class="tab-content">
            <div role="tabpanel" class="tab-pane fade active in" id="alipay">
              <div class="donate-payimg">
                <img src="/myblogs/images/donate/alipayimg.png" alt="扫码支持" title="扫一扫">
              </div>
              <p class="text-muted mv">扫码打赏，你说多少就多少</p>
              <p class="text-grey">打开支付宝扫一扫，即可进行扫码打赏哦</p>
            </div>
            <div role="tabpanel" class="tab-pane fade" id="wechatpay">
              <div class="donate-payimg">
                <img src="/myblogs/images/donate/wechatpayimg.png" alt="扫码支持" title="扫一扫">
              </div>
              <p class="text-muted mv">扫码打赏，你说多少就多少</p>
              <p class="text-grey">打开微信扫一扫，即可进行扫码打赏哦</p>
            </div>
          </div>
          <div class="donate-footer">
            <ul class="nav nav-tabs nav-justified" role="tablist">
              <li role="presentation" class="active">
                <a href="#alipay" id="alipay-tab" role="tab" data-toggle="tab" aria-controls="alipay" aria-expanded="true"><i class="icon icon-alipay"></i> 支付宝</a>
              </li>
              <li role="presentation" class>
                <a href="#wechatpay" role="tab" id="wechatpay-tab" data-toggle="tab" aria-controls="wechatpay" aria-expanded="false"><i class="icon icon-wepay"></i> 微信支付</a>
              </li>
            </ul>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>



</main>

  <footer class="footer" itemscope itemtype="http://schema.org/WPFooter">
	
	
    <ul class="social-links">
    	
        <li><a href="https://github.com/yuzhouStayHungry" target="_blank" title="Github" data-toggle="tooltip" data-placement="top"><i class="icon icon-github"></i></a></li>
        
        <li><a href="https://www.jianshu.com/u/93e9b14c6fbd" target="_blank" title="简书" data-toggle="tooltip" data-placement="top"><i class="icon icon-简书"></i></a></li>
        
        <li><a href="https://www.cnblogs.com/yuzhou-1su/" target="_blank" title="Blog" data-toggle="tooltip" data-placement="top"><i class="icon icon-Blog"></i></a></li>
        
        <li><a href="https://blog.csdn.net/yuzhou_1shu" target="_blank" title="CSDN" data-toggle="tooltip" data-placement="top"><i class="icon icon-CSDN"></i></a></li>
        
        <li><a href="/myblogs/atom.xml" target="_blank" title="Rss" data-toggle="tooltip" data-placement="top"><i class="icon icon-rss"></i></a></li>
        
    </ul>

    <div class="copyright">
    	
        <div class="publishby">
        	Theme by <a href="https://github.com/cofess" target="_blank"> cofess </a>base on <a href="https://github.com/cofess/hexo-theme-pure" target="_blank">pure</a>.
        </div>
    </div>
</footer>
  <script src="//cdn.jsdelivr.net/npm/jquery@1.12.4/dist/jquery.min.js"></script>
<script>
window.jQuery || document.write('<script src="js/jquery.min.js"><\/script>')
</script>
<script src="/myblogs/js/plugin.min.js"></script>
<script src="/myblogs/js/application.js"></script>

    <script>
(function (window) {
    var INSIGHT_CONFIG = {
        TRANSLATION: {
            POSTS: '文章',
            PAGES: '页面',
            CATEGORIES: '分类',
            TAGS: '标签',
            UNTITLED: '(未命名)',
        },
        ROOT_URL: '/myblogs/',
        CONTENT_URL: '/myblogs/content.json',
    };
    window.INSIGHT_CONFIG = INSIGHT_CONFIG;
})(window);
</script>
<script src="/myblogs/js/insight.js"></script>





   




   
    
  <script src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
  <script src="//cdn.jsdelivr.net/npm/valine"></script>
  <script type="text/javascript">
  var GUEST = ['nick', 'mail', 'link'];
  var meta = 'nick,mail,link';
  meta = meta.split(',').filter(function(item) {
    return GUEST.indexOf(item) > -1;
  });
  new Valine({
    el: '#vcomments',
    verify: false,
    notify: false,
    appId: '',
    appKey: '',
    placeholder: 'Just go go',
    avatar: 'mm',
    meta: meta,
    pageSize: '10' || 10,
    visitor: false
  });
  </script>

     







</body>
</html>